package com.greenant.store.activity;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.avos.avoscloud.AVException;
import com.avos.avoscloud.AVQuery;
import com.avos.avoscloud.AVUser;
import com.avos.avoscloud.GetCallback;
import com.avos.avoscloud.SaveCallback;
import com.greenant.store.AntHomeApplication;
import com.greenant.store.R;
import com.greenant.store.adapter.OrderDetailListAdapter;
import com.greenant.store.bean.Order;
import com.greenant.store.bean.OrderItem;
import com.greenant.store.bean.OrderStatusCode;
import com.greenant.store.bean.ShippingAddr;
import com.greenant.store.bean.StoreInfo;
import com.greenant.store.service.RetrieveDataAsyn;
import com.greenant.store.service.RetrieveDataListener;
import com.greenant.store.utils.Const;
import com.greenant.store.utils.NotificationUtil;
import com.greenant.store.utils.SQLiteHelper;
import com.greenant.store.utils.UtilTools;
import com.greenant.store.utils.iLog;
import com.greenant.store.view.CommonDialog;
import com.greenant.store.view.PopMenu;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshScrollView;
import com.lsarah.utils.SystemBarTintManager;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.text.format.DateFormat;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

public class OrderDetailActivity extends BaseActivity {
	public static final String KeySendTime = "key_send_time";
	public static final String KeyGoodsList = "key_goods_list";
	private final String TAG = "OrderDetailActivity";

	private ShippingAddr mShippingAddr;

	private View mBackView;

	private TextView mTvShouldPayMoney;
	private TextView order_goods_total_money;
	// 订单号
	private TextView order_detail_number_desc;
	private TextView orderdetail_user_number_desc;

	private TextView order_send_way;
	private TextView order_create_time;
	private TextView order_pay_time;
	private TextView order_send_time;
	private TextView order_signed_time;
	private TextView order_send_time_real;

	private TextView order_send_method;
	// 订单状态
	private TextView order_detail_status;
	// 运费
	private TextView order_ship_price;

	private TextView order_storeName;
	private Button makeaCall;
	// 收件人信息
	private TextView customername, customerphone, customeraddress, customercomment;

	private Button close;
	private Button payContinue;

	// private Order order;
	private Context context;
	private PullToRefreshScrollView scrollView;

	private ListView orderlist;
	private List<OrderItem> orderItemList = new ArrayList<OrderItem>();
	OrderDetailListAdapter orderDetailListAdapter;
	// 电话号码
	private String teleP = "";

	// 提交按钮
	private TextView modify;

	private RelativeLayout nodataView;
	private LinearLayout dataView;
	private TextView order_detail_hint;
	
	private TextView order_minus_pay_money;

	public static final int MSG_TYPE_FEEDBACK = 0;
	public static final int MSG_TYPE_WEIGHT = 1;

	// 是否需要稱重
	boolean isNeedToweight = false;

	private Handler mHandler = new Handler(Looper.getMainLooper());

	private OnClickListener mOnClickListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			if (v.equals(mBackView)) {
				OrderDetailActivity.this.finish();
			}
		}
	};

	private RetrieveDataListener mRetrieveDataListener = new RetrieveDataListener() {
		@Override
		public void dataRetrieved(int requestId, Object data) {

		}
	};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		SystemBarTintManager.setContentView(this, R.layout.activity_order_detail,
				getResources().getColor(R.color.firebrick));
		context = this;
		mBackView = findViewById(R.id.order_create_top_arrow_left);
		// mBtnCreateOrder = (Button) findViewById(R.id.order_create_btn);
		mTvShouldPayMoney = (TextView) findViewById(R.id.order_create_should_pay_money);
		// mTvTotalMoney = (TextView)
		// findViewById(R.id.order_create_total_money);
		order_detail_number_desc = (TextView) findViewById(R.id.order_detail_number_desc);
		orderdetail_user_number_desc = (TextView) findViewById(R.id.orderdetail_user_number_desc);
		order_create_time = (TextView) findViewById(R.id.order_create_time);
		order_signed_time = (TextView) findViewById(R.id.order_signed_time);
		order_send_time_real = (TextView) findViewById(R.id.order_send_time_real);
		order_detail_status = (TextView) findViewById(R.id.order_detail_status);
		order_goods_total_money = (TextView) findViewById(R.id.order_goods_total_money);
		order_pay_time = (TextView) findViewById(R.id.order_pay_time);
		close = (Button) findViewById(R.id.close);
		payContinue = (Button) findViewById(R.id.payContinue);
		makeaCall = (Button) findViewById(R.id.makeaCall);
		orderlist = (ListView) findViewById(R.id.orderlist);
		order_detail_hint = (TextView) findViewById(R.id.order_detail_hint);
		
		order_minus_pay_money= (TextView) findViewById(R.id.order_minus_pay_money);
		// order_refresh = findViewById(R.id.order_refresh);
		scrollView = (PullToRefreshScrollView) findViewById(R.id.scrollView);
		scrollView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener<ScrollView>() {

			@Override
			public void onRefresh(PullToRefreshBase<ScrollView> refreshView) {
				refreshOrderDetail();
			}
		});

		nodataView = (RelativeLayout) findViewById(R.id.nodataView);
		dataView = (LinearLayout) findViewById(R.id.dataView);

		order_send_way = (TextView) findViewById(R.id.order_send_way);
		order_storeName = (TextView) findViewById(R.id.order_storeName);
		// makeCallTitle = (TextView) findViewById(R.id.makeCallTitle);

		order_send_time = (TextView) findViewById(R.id.order_send_time);
		order_send_method = (TextView) findViewById(R.id.order_send_method);
		order_ship_price = (TextView) findViewById(R.id.order_ship_price);

		// 收件人信息
		customername = (TextView) findViewById(R.id.customername);
		customerphone = (TextView) findViewById(R.id.customerphone);
		customeraddress = (TextView) findViewById(R.id.customeraddress);
		customercomment = (TextView) findViewById(R.id.customercomment);

		modify = (TextView) findViewById(R.id.modify);

		mBackView.setOnClickListener(mOnClickListener);
		// mBtnCreateOrder.setOnClickListener(mOnClickListener);
		orderDetailListAdapter = new OrderDetailListAdapter(orderItemList, this);

		orderlist.setAdapter(orderDetailListAdapter);

		modify.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				processOrder();
			}
		});

		order_detail_hint.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent(context, OrderDescActivity.class);
				startActivityForResult(intent, MSG_TYPE_FEEDBACK);
			}
		});
		initData();
	}

	private void processOrder() {
		if (Const.order == null) {
			return;
		}
		final int statusCode = Const.order.getStatusCode();
		final PopMenu popMenu = new PopMenu(this);
		boolean isNeedPop = false;

		isNeedToweight = false;
		if (Const.order.isHaveWeight()) {
			if (!Const.order.isWeighted()) {
				isNeedToweight = true;
			}
		}
		switch (OrderStatusCode.values()[statusCode]) {
		case ORDER_PENDING:// 0 -待发货
			if (isNeedToweight) {
				String[] detailmenus = { context.getString(R.string.orderdetail_weight_action),
						context.getString(R.string.order_cancel) };
				popMenu.addItems(detailmenus, null);
			} else {
				if(Const.order.isPayed())
				{
					String[] detailmenus = { context.getString(R.string.shipped),
							context.getString(R.string.order_cancel) };
					popMenu.addItems(detailmenus, null);	
				}
				else{
					String[] detailmenus2 = { context.getString(R.string.order_cancel) };
					popMenu.addItems(detailmenus2, null);	
				}
				
			}
			isNeedPop = true;
			break;
		case ORDER_WAIT_FOR_PAY:// 4-待付款
			String[] detailmenus1 = { context.getString(R.string.order_detail_refresh),
					context.getString(R.string.order_cancel) };
			popMenu.addItems(detailmenus1, null);
			isNeedPop = true;
			break;
		case ORDER_WEIGHED:// 9-已称重
			// 已经支付，可申请退货，关闭订单
			if(Const.order.isPayed())
			{
				String[] detailmenus2 = { context.getString(R.string.shipped), context.getString(R.string.order_cancel) };
				popMenu.addItems(detailmenus2, null);
			}
			else{
				String[] detailmenus2 = { context.getString(R.string.order_cancel) };
				popMenu.addItems(detailmenus2, null);	
			}
			
			isNeedPop = true;
			break;
		case ORDER_REFUNDING:// 6-退款中
			// 同意退款
			modify.setText(R.string.order_refund_accept);
			modifyOrderStatus(OrderStatusCode.ORDER_REFUND_ACCEPT.value());
			break;
		case ORDER_SHIPPED:// 1-已发货
		case ORDER_WAIT_FOR_SIGN:// 5-待收货
		case ORDER_2_STATION:// 2-已送至自提点
			// TODO 等待客户签收
			break;
		case ORDER_REFUNDED:// 7-已退款
		case ORDER_REFUND_ACCEPT: // 10-同意退款
		case ORDER_CANCELED: // 11-已取消
		case ORDER_FINISHED:// 8-已完成
		case ORDER_SIGNED:// 3-已签收
			// 关闭订单

			modifyOrderStatus(OrderStatusCode.ORDER_CLOSED.value());
			break;
		case ORDER_CLOSED: // 12-已关闭
			modify.setVisibility(View.INVISIBLE);
			break;
		default:
			break;
		}

		popMenu.setOnItemClickListener(new AdapterView.OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
				popMenu.dismiss();
				boolean isSend = false;
				switch (OrderStatusCode.values()[statusCode]) {
				case ORDER_PENDING:// 0 -待发货
					String[] detailmenus = { context.getString(R.string.shipped),
							context.getString(R.string.order_cancel) };

					if (isNeedToweight) {
						if (arg2 == 0) {
							Intent intent = new Intent(context, WeightGoodsActivity.class);
							startActivityForResult(intent, OrderDetailActivity.MSG_TYPE_WEIGHT);
						} else if (arg2 == 1) {
							modifyOrderStatus(OrderStatusCode.ORDER_CANCELED.value());
						}
					} else {
						
						if(Const.order.isPayed())
						{
							if (arg2 == 0) {
								modifyOrderStatus(OrderStatusCode.ORDER_SHIPPED.value());
								sendShipedHint();
							} else if (arg2 == 1) {
								modifyOrderStatus(OrderStatusCode.ORDER_CANCELED.value());
							}
						}
						else{
							 if (arg2 == 0) {
								modifyOrderStatus(OrderStatusCode.ORDER_CANCELED.value());
							}
						}
						
					}

					break;
				case ORDER_WAIT_FOR_PAY:// 4-待付款
					if (arg2 == 0) {
						saveOrderDetail();
					} else if (arg2 == 1) {
						modifyOrderStatus(OrderStatusCode.ORDER_REFUND_ACCEPT.value());
					}
					break;
				case ORDER_WEIGHED:// 9-已称重
					// 已经支付，可申请退货，关闭订单
					if (Const.order.isPayed()) {

						if (arg2 == 0) {
							modifyOrderStatus(OrderStatusCode.ORDER_SHIPPED.value());
							sendShipedHint();
						} else if (arg2 == 1) {
							modifyOrderStatus(OrderStatusCode.ORDER_CANCELED.value());
						}
					} else {
						if (arg2 == 0) {
							modifyOrderStatus(OrderStatusCode.ORDER_CANCELED.value());
						}
					}
					break;

				}

			}
		});
		if (isNeedPop) {
			popMenu.showAsDropDown(modify);

		}

	}

	private void sendShipedHint() {
		// 0代表订单消息
		NotificationUtil.sendPrivateMsg(context.getString(R.string.orderdetail_send_hint, Const.order.getOrderId()),
				Const.order.getOrderId(), 0, Const.order.getCustomId());
	}

	private void modifyOrderStatus(final int orderStatus) {
		if (orderStatus == OrderStatusCode.ORDER_SHIPPED.value()) {
			Date date = new Date();
			date.setTime(System.currentTimeMillis());
			Const.order.setSendTime(date);
		}

		if (orderStatus == OrderStatusCode.ORDER_CANCELED.value()) {
			CommonDialog dialog = new CommonDialog(context, context.getString(R.string.common_title),
					context.getString(R.string.button_order_cancel_hint));
			dialog.setSureListener(new CommonDialog.OnSureClickListener() {

				@Override
				public void sureClicked() {

					

					RetrieveDataAsyn.getInstance().updateOrderStatus(Const.order, orderStatus, 0,
							new RetrieveDataListener() {

						@Override
						public void dataRetrieved(int requestId, Object data) {
							if (data == null) {
								UtilTools.showMyToast(context, context.getString(R.string.order_msssage_modify_fail));
							} else {
								UtilTools.showMyToast(context, context.getString(R.string.order_msssage_modify_succ));
								Const.order.setStatusCode(orderStatus);
								if (Const.order.getFavorableCost() > 0.001) {

									AVQuery<AVUser> users = AVUser.getQuery();
									users.getInBackground(Const.order.getCustomId(), new GetCallback<AVUser>() {

										@Override
										public void done(AVUser user, AVException arg1) {
											if (user != null) {
												// 取消订单的时候将首单减免去掉
												user.put("firstOrderDiscountUsed", false);
												user.saveInBackground();
											}
										}
									});
								}
								initData();
							}
						}
					});
				}
			});
			dialog.show();
		} else {
			RetrieveDataAsyn.getInstance().updateOrderStatus(Const.order, orderStatus, 0, new RetrieveDataListener() {

				@Override
				public void dataRetrieved(int requestId, Object data) {
					if (data == null) {
						UtilTools.showMyToast(context, context.getString(R.string.order_msssage_modify_fail));
					} else {
						UtilTools.showMyToast(context, context.getString(R.string.order_msssage_modify_succ));
						Const.order.setStatusCode(orderStatus);
						initData();
					}
				}
			});
		}

	}

	@Override
	protected void onPause() {
		super.onPause();
		Intent intent = new Intent(Const.ORDER_STATUS_CHANGED);
		sendBroadcast(intent);
	}

	private void saveOrderDetail() {

		if (Const.order != null) {
			double shipPrice = 0;
			try {
				shipPrice = Double.parseDouble(order_ship_price.getText().toString());
			} catch (NumberFormatException e) {
				e.printStackTrace();
			}
			Const.order.setDeliveryCost(shipPrice);
			Const.order.saveOrderItems(orderItemList);
			Const.order.setComment(order_detail_hint.getText().toString());

			// Const.order.set
			Const.order.saveInBackground(new SaveCallback() {

				@Override
				public void done(final AVException arg0) {
					mHandler.post(new Runnable() {

						@Override
						public void run() {
							if (arg0 == null) {
								UtilTools.showMyToast(context, context.getString(R.string.order_msssage_modify_succ));
							} else {
								UtilTools.showMyToast(context, context.getString(R.string.order_msssage_modify_fail));
							}
						}
					});
				}
			});
		}

	}

	private void refreshOrderDetail() {

		dataView.setVisibility(View.INVISIBLE);
		nodataView.setVisibility(View.VISIBLE);
		if (Const.order != null) {

			RetrieveDataAsyn.getInstance().getOrderDetail(Const.order.getObjectId(), 0, new RetrieveDataListener() {

				@Override
				public void dataRetrieved(int requestId, Object data) {

					if (data != null) {
						Order tempOrder = (Order) data;

						Const.order.put(Order.ATTR_ORDERITEMS, tempOrder.getString(Order.ATTR_ORDERITEMS));

						Const.order.setStatusCode(tempOrder.getStatusCode());
						Const.order.setAddress(tempOrder.getAddress());
						Const.order.setOrderType(tempOrder.getOrderType());
						Const.order.setPayWay(tempOrder.getPayWay());
						Const.order.setDeliveryTime(tempOrder.getDeliveryTime());
						Const.order.setDeliveryWay(tempOrder.getDeliveryWay());
						Const.order.setPayTime(tempOrder.getPayTime());
						Const.order.setTotalCost(tempOrder.getTotalCost());
						Const.order.setDeliveryCost(tempOrder.getDeliveryCost());
						Const.order.setPayed(tempOrder.isPayed());
						initData();

					}
					dataView.setVisibility(View.VISIBLE);
					nodataView.setVisibility(View.INVISIBLE);
					scrollView.onRefreshComplete();
				}
			});

		} else {
			dataView.setVisibility(View.VISIBLE);
			nodataView.setVisibility(View.INVISIBLE);
		}

	}

	private void initData() {
		if (Const.order == null) {
			return;
		}
		// 保存已读状态
		if (Const.order.getIsMarkRead() == 0) {
			Const.order.setMarkRead();
			Const.order.saveInBackground(new SaveCallback() {

				@Override
				public void done(AVException arg0) {

				}
			});
		}
		// 订单创建时间
		order_create_time.setText(DateFormat.format("yyyy-MM-dd HH:mm:ss", Const.order.getCreatedAt()));
		if (Const.order.getPayTime() != null) {
			order_pay_time.setText(DateFormat.format("yyyy-MM-dd HH:mm:ss", Const.order.getPayTime()));
		}
		if (Const.order.getSignedTime() != null) {
			order_signed_time.setText(DateFormat.format("yyyy-MM-dd HH:mm:ss", Const.order.getSignedTime()));
		}
		if (Const.order.getSendTime() != null) {
			order_send_time_real.setText(DateFormat.format("yyyy-MM-dd HH:mm:ss", Const.order.getSendTime()));
		}

		// // 订单号
		order_detail_number_desc.setText(Const.order.getOrderId());
		AVQuery<AVUser> avUser = AVUser.getQuery();
		try {
			avUser.getInBackground(Const.order.getCustomId(), new GetCallback<AVUser>() {

				@Override
				public void done(AVUser arg0, AVException arg1) {
					if (arg1 == null) {
						// 获取下单帐号名称
						orderdetail_user_number_desc.setText(arg0.getUsername());
					}

				}
			});
		} catch (Exception e1) {
			e1.printStackTrace();
		}

		orderItemList.clear();
		List<OrderItem> items = Const.order.getOrderItems();
		iLog.d(TAG, "tempList1 getOrderItems size:" + items.size() + " orderItemList:" + orderItemList.size());
		orderItemList.addAll(items);

		for (int i = 0; i < items.size(); i++) {
			iLog.d(TAG, "tempList1 getOrderItems items:" + items.get(i).getWeight() + " items size:" + items.size()
					+ " orderItemList:" + orderItemList.size());
		}
		setListViewHeight(orderlist);
		double totalCost = UtilTools.getTotalCostByOrderItems(orderItemList);

		StoreInfo storeInfo = AntHomeApplication.storeInfos.get(Const.order.getStoreId());
		if (storeInfo != null) {
			double startCost = storeInfo.getStartcost();

			iLog.d("startCost:" + startCost + "");
			if (startCost > totalCost) {
				Const.order.setDeliveryCost(storeInfo.getDeliverycost());
			} else {
				Const.order.setDeliveryCost(0);
			}
			iLog.d("startCost:" + startCost + " DeliveryCost:" + Const.order.getDeliveryCost());
		}
		
		if(AntHomeApplication.context.getResources().getString(R.string.order_ensure_send_metho_ziting).equals(Const.order.getDeliveryWay()))
		{
			Const.order.setDeliveryCost(0);
		}

		// 应付总金额
		if (totalCost < 0.00001) {
			mTvShouldPayMoney.setText("--.--");
			order_goods_total_money.setText("--.--");
		} else {
			order_goods_total_money.setText(String.valueOf(totalCost));
			totalCost += Const.order.getDeliveryCost();
			totalCost-=Const.order.getFavorableCost();
			mTvShouldPayMoney.setText(String.valueOf(totalCost));
		}

		order_ship_price.setText("" + Const.order.getDeliveryCost());

		orderDetailListAdapter.notifyDataSetChanged();

		if (!TextUtils.isEmpty(Const.order.getComment())) {
			order_detail_hint.setText(Const.order.getComment());
		}

		order_storeName.setVisibility(View.VISIBLE);
		String deliveryWay = Const.order.getDeliveryWay();

		if (Const.order.isSp()) {

		} else {
			try {
				order_storeName.setText(AntHomeApplication.storeInfos.get(Const.order.getStoreId()).getDescrip());

				teleP = AntHomeApplication.storeInfos.get(Const.order.getStoreId()).getPhone();
			} catch (Exception e) {
				e.printStackTrace();
			}

		}
		if (this.getString(R.string.order_ensure_send_metho_ziting).equals(deliveryWay)) {
			String pickUpId = Const.order.getPickUpStationId();
			if (!TextUtils.isEmpty(pickUpId)) {
				order_storeName.setText(String.format(this.getString(R.string.orderdetail_pickup), pickUpId));
			}
		}
		order_send_method.setText(deliveryWay);
		Date deliverTime = Const.order.getDeliveryTime();
		if (deliverTime != null) {
			if (deliverTime.getTime() <= System.currentTimeMillis()) {
				order_send_time.setText(R.string.order_ensure_send_time_right_now);
			} else {
				order_send_time.setText(DateFormat.format("yyyy-MM-dd HH:mm:ss", deliverTime));
			}
		}
		customername.setText(Const.order.getConsignee());
		customerphone.setText(Const.order.getPhone());
		customeraddress.setText(Const.order.getAddress());
		customercomment.setText(Const.order.getCustomRemark());

		if (TextUtils.isEmpty(Const.order.getPhone())) {
			makeaCall.setVisibility(View.GONE);
			// makeCallTitle.setVisibility(View.GONE);
		}
		// 支付方式
		order_send_way.setText(Const.order.getPayWay());
		processOrderStatus();
		mHandler.postDelayed(new Runnable() {

			@Override
			public void run() {
				scrollView.scrollTo(0, 0);
			}
		}, 200);
		// 处理提交按钮按时的状态
		processModifyText();
		order_minus_pay_money.setText(""+Const.order.getFavorableCost());
	}

	private void processModifyText() {

		if (Const.order == null) {
			return;
		}
		modify.setVisibility(View.VISIBLE);
		modify.setText(R.string.dispose);

		int statusCode = Const.order.getStatusCode();
		switch (OrderStatusCode.values()[statusCode]) {
		case ORDER_PENDING:// 0 -待发货
			break;
		case ORDER_WAIT_FOR_PAY:// 4-待付款
			break;
		case ORDER_WEIGHED:// 9-已称重
			// 已经支付，可申请退货，关闭订单
			break;
		case ORDER_REFUNDING:// 6-退款中
			// 同意退款
			modify.setText(R.string.order_refund_accept);
			break;
		case ORDER_WAIT_FOR_SIGN:// 5-待收货
		case ORDER_2_STATION:// 2-已送至自提点
			// TODO 等待客户签收
			break;
		case ORDER_REFUNDED:// 7-已退款
		case ORDER_REFUND_ACCEPT: // 10-同意退款
		case ORDER_CANCELED: // 11-已取消
		case ORDER_FINISHED:// 8-已完成
		case ORDER_SIGNED:// 3-已签收
			// 关闭订单
			modify.setText(R.string.order_detail_close_order);
			break;
		case ORDER_SHIPPED:// 1-已发货
		case ORDER_CLOSED: // 12-已关闭
			modify.setVisibility(View.INVISIBLE);
			break;
		default:
			break;
		}

	}

	public void makeaCall(View view) {

		final String tele = Const.order.getPhone();
		if (!TextUtils.isEmpty(tele)) {
			CommonDialog errDialog = new CommonDialog(context,
					context.getString(R.string.common_title), context.getString(R.string.orderdetail_call));
			errDialog.setSureListener(new CommonDialog.OnSureClickListener() {

				@Override
				public void sureClicked() {
					Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + tele));
					startActivity(intent);
				}
			});
			errDialog.show();

		}

	}

	/**
	 * 重新计算ListView的高度，解决ScrollView和ListView两个View都有滚动的效果，在嵌套使用时起冲突的问题
	 * 
	 * @param listView
	 */
	public void setListViewHeight(ListView listView) {

		// 获取ListView对应的Adapter

		ListAdapter listAdapter = listView.getAdapter();

		if (listAdapter == null) {
			return;
		}
		int totalHeight = 0;
		for (int i = 0, len = listAdapter.getCount(); i < len; i++) { // listAdapter.getCount()返回数据项的数目
			View listItem = listAdapter.getView(i, null, listView);
			listItem.measure(0, 0); // 计算子项View 的宽高
			totalHeight += listItem.getMeasuredHeight(); // 统计所有子项的总高度
		}

		ViewGroup.LayoutParams params = listView.getLayoutParams();
		params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
		listView.setLayoutParams(params);
	}

	/**
	 * 处理初始订单状态界面，button，status，注册监听等
	 * 
	 * @since 3.8
	 */
	private void processOrderStatus() {
		processOrderButton();
	}

	/**
	 * 处理button，status,刷新界面
	 * 
	 * @since 3.8
	 */
	private void processOrderButton() {
		UtilTools.processOrderStatus(close, payContinue, order_detail_status, context, Const.order);

	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		Log.d("CEXX", "CEXX ---> OrderCreateActivity ---> requestCode : " + requestCode);
		Log.d("CEXX", "CEXX ---> OrderCreateActivity ---> resultCode : " + resultCode);
		switch (requestCode) {
		case MSG_TYPE_FEEDBACK:
			if (resultCode == RESULT_OK) {
				order_detail_hint.setText(Const.order.getComment());
			}
			break;
		case MSG_TYPE_WEIGHT:
			if (resultCode == RESULT_OK) {

				initData();
			}
			break;

		}

	}

}
